<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #canvas {
            border: 1px solid #333;
        }
    </style>
</head>

<body>
    <canvas id="canvas" width="200" height="200"></canvas>
    <script>
        /* 1、获取DOM */
        let canvas = document.getElementById("canvas");
        /* 2、获取绘制上下文 ctx */
        let ctx = canvas.getContext("2d");
        /* 设置路径 */
        ctx.moveTo(0, 0)  //设置路径的起点坐标
        ctx.lineTo(100, 100) //设置路径的中的坐标
        ctx.lineWidth = 5;
        ctx.strokeStyle = "#ff2d51"
        ctx.stroke();
    </script>
</body>

</html>